
/** I N C L U D E S **********************************************************/
#include <p18f4550.h>

/** V A R I A B L E S ********************************************************/
#pragma udata

/** P R I V A T E  P R O T O T Y P E S ***************************************/

/** V E C T O R  R E M A P P I N G *******************************************/

void main (void);
void InterruptHandlerHigh (void);

extern void _startup (void);        // See c018i.c in your C18 compiler dir
#pragma code _RESET_INTERRUPT_VECTOR = 0x000800
void _reset (void)
{
    _asm goto _startup _endasm
}
#pragma code

#pragma code _HIGH_INTERRUPT_VECTOR = 0x000808
void _high_ISR (void)
{
  _asm
    goto InterruptHandlerHigh //jump to interrupt routine
  _endasm
}

#pragma code _LOW_INTERRUPT_VECTOR = 0x000818
void _low_ISR (void)
{
    ;
}
#pragma code

/** D E C L A R A T I O N S **************************************************/
#pragma code	
void delay(void)
{
	int i=30000;
	while(i--);
}
void main (void)
{
	INTCON = 0x20;                //disable global and enable TMR0 interrupt
	INTCON2 = 0x84;               //TMR0 high priority
	RCONbits.IPEN = 1;            //enable priority levels
	TMR0H = 0;                    //clear timer
	TMR0L = 0;                    //clear timer
	T0CON = 0x82;                 //set up timer0 - prescaler 1:8
	INTCONbits.GIEH = 1;          //enable interrupts
	TRISD=0;
	while(1)
	{
	}
}
//----------------------------------------------------------------------------
// High priority interrupt routine

#pragma code
#pragma interrupt InterruptHandlerHigh

void InterruptHandlerHigh ()
{
  if (INTCONbits.TMR0IF)
    {                                   //check for TMR0 overflow
      INTCONbits.TMR0IF = 0;            //clear interrupt flag
      PORTDbits.RD1=~PORTDbits.RD1;		//toggle
    }
}

//----------------------------------------------------------------------------
